import httpFetch from 'share/httpFetch';
import config from 'config';
import errorMessage from "share/errorMessage";
import moment from 'moment'

export default {
  /**
   * 获取滴滴消费记录
   * @param {String} start
   * @param {String} end
   */
  getDiDiList(pagination, searchCondition) {
    const params = {
      page: pagination.page,
      size: pagination.size,
      ...searchCondition
    };
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/didiV3/queryOrderList`, params).then((res) => {
        resolve(res);
      }).catch((err) => {
        errorMessage(err.response);
        reject(err.response);
      });
    });
  },
  /**
   * 根据orderId获取滴滴消费记录
   * @param {String} paramsStr orderId数组拼成的字符串 比如 1, 2, 3
   */
  getDiDiInfoByOrderId(paramsStr) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/didiV3/queryOrderListByOrderId?orderIdArray=${paramsStr}`).then((res) => {
        resolve(res);
      }).catch((err) => {
        errorMessage(err.response);
        reject(err.response);
      });
    });
  },
  /**
  * 根据id数组获取这些id对应的滴滴消费详情
  */
  getRecordsByIds(ids) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/didi/v3/order/detail?ids=${ids.join(',')}`).then((res) => {
        resolve(res);
      }).catch(err => {
        errorMessage(err.response);
        reject(err.response);
      });
    })
  },
  /**
   * 公务卡消费转因私
   */
  toBorrow (paramsBody, paramsUrl) {
    let url = `${config.baseUrl}/api/bankbill/relation/didi`
    const keysArr = Object.keys(paramsUrl)
    if (keysArr.length > 0) {
      keysArr.map((key, index) => {
        if (index === 0) {
          url = `${url}?${key}=${paramsUrl[key]}`
        } else {
          url = `${url}&${key}=${paramsUrl[key]}`
        }
      })
    }
    return new Promise((resolve, reject) => {
      httpFetch.put(encodeURI(url), paramsBody).then((res) => {
        resolve(res);
      }).catch(err => {
        errorMessage(err.response);
        reject(err.response);
      });
    })
  },
  getProxyPrincipals() {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/bill/proxy/query/my/principals?operationCode=3&roleType=TENANT`).then((res) => {
        resolve(res);
      }).catch((err) => {
        errorMessage(err.response);
        reject(err.response);
      });
    })
  },
    /**
   * 获取滴滴消费记录
   */
    getDiDiMoneyList(pagination, searchCondition) {
      return new Promise((resolve, reject) => {
        httpFetch.get(`${config.baseUrl}/api/didi/v3/quota/by/cgm`).then((res) => {
          resolve(res);
        }).catch((err) => {
          errorMessage(err.response);
          reject(err.response);
        });
      });
    },

};
